using System;
using Impact.Model.Objects;

namespace Impact.Model.Service
{
    public class ProfileService : IProfileService
    {
        #region IProfileService Members

        /// <summary>
        /// retrieve all profiles
        /// </summary>
        /// <returns></returns>
        public ProfileCollection FetchProfiles( bool onlyEnabled )
        {
            ProfileCollection output = new ProfileCollection();
            if ( onlyEnabled )
            {
                output.Where( Profile.Columns.Enabled, true );
            }
            return output.OrderByAsc( Profile.Columns.CompanyName ).Load();
        }

        /// <summary>
        /// fetch a single profile for modification
        /// </summary>
        public Profile FetchProfile( int profileId )
        {
            return Profile.FetchByID( profileId );
        }

        public Profile FetchProfile( string columnName, string value )
        {
            return new Profile( columnName, value );
        }

        /// <summary>
        /// save the given page with the given userId as responsible for the changes
        /// </summary>
        public void Save( Profile profile, Guid userId )
        {
            profile.Save( userId );
        }

        public void Remove( int profileId )
        {
            Profile.Delete( profileId );
        }

        #endregion
    }
}
